//
//  MovieTableViewCell.m
//  豆瓣_精简版
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MovieTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation MovieTableViewCell

- (void)dealloc
{
    [_nameLabel release];
    [_headImageView release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatSubView];
    }
    return self;
}

- (void)creatSubView{
    
    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 355, 160)];
    imageView1.image = [UIImage imageNamed:@"bg_eventlistcell@2x.png"];
    [self.contentView addSubview:imageView1];
    [imageView1 release];
    
    self.headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 100, 140)];
    self.headImageView.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.headImageView];
    
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(140, 65, 200, 50)];
    self.nameLabel.font = [UIFont systemFontOfSize:20];
    [self.contentView addSubview:self.nameLabel];
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(300, 30, 30, 30);
    [self.button setBackgroundImage:[UIImage imageNamed:@"check@2x.png"] forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button];
    
    
    [self.headImageView release];
    [self.nameLabel release];
}

- (void)buttonAction:(UIButton *)but{
    
    if (self.isSelected == NO) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"checked@2x.png"] forState:UIControlStateNormal];
        NSLog(@"%ld",self.myIndexPath.row);
    }else{
        [self.button setBackgroundImage:[UIImage imageNamed:@"check@2x.png"] forState:UIControlStateNormal];
    }
    self.isSelected = !self.isSelected;
    
}

-(void)setMovie:(Movie *)movie{
    
    if (_movie != movie) {
        [_movie release];
        _movie = [movie retain];
    }
    
    self.nameLabel.text = movie.movieName;
    NSURL *url = [NSURL URLWithString:movie.pic_url];
    [self.headImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeHoderImage.png"]];
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
